package dao

import (
	"ginfast/pkg/gctx"
	"ginfast/util"

	"github.com/gin-gonic/gin"
)

func Deletes(v interface{}, c *gin.Context) {
	idstr := c.Param("id")
	if idstr != "" {
		ids := util.StringToIntSlice(idstr, ",")
		if err := DbDeleteByIds(v, ids); err != nil {
			gctx.JSONWriteError(err, c)
			return
		}
	}
	gctx.JSONOK(c)
}

func QueryByID(v interface{}, c *gin.Context) {
	queryId := gctx.ParamUInt(c, "id")
	if err := DbFirstById(v, queryId); err != nil {
		gctx.JSONWriteError(err, c)
		return
	}
	gctx.JSONWriteData(v, c)
}
